import 'package:flutter/material.dart';

import '../widget/MyButton.dart';

// 支付页面
class PayPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => PayState();
}

class PayState extends State {
  int checkedIndex = 0;

  List data = [
    {
      "img": "https://www.itying.com/themes/itying/images/alipay.png",
      "title": "支付宝支付"
    },
    {
      "img": "https://www.itying.com/themes/itying/images/weixinpay.png",
      "title": "微信支付"
    },
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('去支付')),
      body: ListView(padding: EdgeInsets.all(10), children: [
        ListView.builder(
          shrinkWrap: true,
          itemCount: data.length,
          itemBuilder: (BuildContext context, int index) {
            return Column(
              children: [
                ListTile(
                  leading: Image.network(data[index]['img']),
                  title: Text(data[index]['title']),
                  trailing: checkedIndex == index ? Icon(Icons.check) : null,
                  onTap: (){
                    this.setState(() {
                      this.checkedIndex = index;
                    });
                  },
                ),
                Divider(height: 30),
              ],
            );
          },
        ),
        SizedBox(height: 80),
        MyButton(
          text: '支付',
          color: Colors.red,
          cb: (){
              Navigator.pushNamed(context, '/order');
          },
        )
      ]),
    );
  }
}
